package com.sakura.mall.product.categoryBrandRelation.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.product.categoryBrandRelation.domain.request.AddCategoryBrandRelationRequest;
import com.sakura.mall.product.categoryBrandRelation.domain.request.UpdateCategoryBrandRelationRequest;
import com.sakura.mall.product.categoryBrandRelation.domain.request.CategoryBrandRelationPageRequest;
import com.sakura.mall.product.categoryBrandRelation.service.CategoryBrandRelationService;
import com.sakura.mall.product.categoryBrandRelation.domain.vo.CategoryBrandRelationVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌分类关联
 *
 * @author sakura
 */
@RestController
@RequestMapping("/categoryBrandRelation")
@RequiredArgsConstructor
public class CategoryBrandRelationController {

    private final CategoryBrandRelationService categoryBrandRelationService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddCategoryBrandRelationRequest request) {
        categoryBrandRelationService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<CategoryBrandRelationVo>}
     */
    @GetMapping("list")
    public R<Page<CategoryBrandRelationVo>> page(CategoryBrandRelationPageRequest request) {
        Page<CategoryBrandRelationVo> ret = categoryBrandRelationService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        categoryBrandRelationService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateCategoryBrandRelationRequest request) {
        categoryBrandRelationService.updateById(id, request);
        return R.ok();
    }

}
